<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增申请')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
    <style>
        body{
            width: 100%;
            height: 100%;
            background-position: center;
        }
        .input{
            width: 40px;
            border: none;
            outline: none;
        }
        .input:focus{
            outline: none;
        }
        .inputP{
            width: 40px;
            border: none;
            outline: none;
        }
        .inputP:focus{
            outline: none;
        }
        .inputN{
            width: 40px;
            border: none;
            outline: none;
        }
        .inputN:focus{
            outline: none;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-apply-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">岗位ID：</label>
                <div class="col-sm-8">
                    <input name="postId" th:value="${postId}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">学生ID：</label>
                <div class="col-sm-8">
                    <input name="studentId" th:value="${user.userId}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group" hidden>
                <label class="col-sm-3 control-label">时间ID：</label>
                <div class="col-sm-8">
                    <input name="freeId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">时间：</label>
                <div class="col-sm-8">
                    <table border=6 bordercolor="#000000" frame=void align=center width=900px height=100px cellspacing=0px cellpadding=10px>
                        <tr height=40px align=center>
                            <th width=100px bgcolor="orchid">星期</th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期一</font>
                            </th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期二</font>
                            </th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期三</font>
                            </th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期四</font>
                            </th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期五</font>
                            </th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期六</font>
                            </th>
                            <th bgcolor="mediumaquamarine">
                                <font>星期日</font>
                            </th>
                        </tr>
                        <input name="times[0].postId" th:value="${postId}" type="text" hidden>
                        <input name="times[1].postId" th:value="${postId}" type="text" hidden>
                        <input name="times[2].postId" th:value="${postId}" type="text" hidden>
                        <input name="times[0].userId" th:value="${user.userId}"   type="text" hidden>
                        <input name="times[1].userId" th:value="${user.userId}"   type="text" hidden>
                        <input name="times[2].userId" th:value="${user.userId}"   type="text" hidden>
                        <tr height=40px align=center>
                            <td bgcolor="skyblue">
                                <font><b>上午</b></font>
                            </td>
                            <input type="text" name="times[0].time" th:value="1" hidden/>
                            <td><input name="times[0].monday" id="am1" class="input" th:value="无"/></td>
                            <td><input name="times[0].tuesday" id="am2" class="input" th:value="无"/></td>
                            <td><input name="times[0].wednesday" id="am3" class="input" th:value="无"/></td>
                            <td><input name="times[0].thursday" id="am4" class="input" th:value="无"/></td>
                            <td><input name="times[0].friday" id="am5" class="input" th:value="无"/></td>
                            <td><input name="times[0].saturday" id="am6" class="input" th:value="无"/></td>
                            <td><input name="times[0].sunday" id="am7" class="input" th:value="无"/></td>
                        </tr>
                        <tr height=40px align=center>
                            <td bgcolor="skyblue">
                                <font><b>下午</b></font>
                            </td>
                            <input type="text" name="times[1].time" th:value="2" hidden/>
                            <td><input name="times[1].monday" id="pm1" class="inputP" th:value="无"/></td>
                            <td><input name="times[1].tuesday" id="pm2" class="inputP" th:value="无"/></td>
                            <td><input name="times[1].wednesday" id="pm3" class="inputP" th:value="无"/></td>
                            <td><input name="times[1].thursday" id="pm4" class="inputP" th:value="无"/></td>
                            <td><input name="times[1].friday" id="pm5" class="inputP" th:value="无"/></td>
                            <td><input name="times[1].saturday" id="pm6" class="inputP" th:value="无"/></td>
                            <td><input name="times[1].sunday" id="pm7" class="inputP" th:value="无"/></td>
                        </tr>
                        <tr height=40px align=center>
                            <td bgcolor="skyblue">
                                <font><b>晚上</b></font>
                            </td>
                            <input type="text" name="times[2].time" th:value="3" hidden/>
                            <td><input name="times[2].monday" id="night1" class="inputN" th:value="无"/></td>
                            <td><input name="times[2].tuesday" id="night2" class="inputP" th:value="无"/></td>
                            <td><input name="times[2].wednesday" id="night3" class="inputN" th:value="无"/></td>
                            <td><input name="times[2].thursday" id="night4" class="inputN" th:value="无"/></td>
                            <td><input name="times[2].friday" id="night5" class="inputN" th:value="无"/></td>
                            <td><input name="times[2].saturday" id="night6" class="inputN" th:value="无"/></td>
                            <td><input name="times[2].sunday" id="night7" class="inputN" th:value="无"/></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">技能、特长：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="experience">
                    <div class="summernote" id="experience"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">勤工助学经历：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="evaluate" placeholder="在校期间勤工助学经历及受资助情况">
                    <div class="summernote" id="evaluate"></div>
                </div>
            </div>
            <div class="form-group" hidden>
                <label class="col-sm-3 control-label">创建者ID：</label>
                <div class="col-sm-8">
                    <input name="createUserId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text">
                </div>
            </div>
        </form>
        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>提 交</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "wstudy/apply"
        var prefixPro =ctx + "wstudy/process";
        var prefixTime =ctx + "wstudy/time";
        let post = [[${post}]]
        $("#form-apply-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            let params2 = {
                "receiveUserId":[[${post.createUserId}]],
                "status":"no",
                "content":"消息提醒：有学生申请岗位，请注意查看！",
                "type":"消息提醒"
            }
            if ($.validate.form()) {
                $.operate.save(prefixPro + "/apply", $('#form-apply-add').serialize(),function () {
                    $.operate.post( prefixTime+"/apply",$('#form-apply-add').serialize())
                    $.operate.post( "/wstudy/message/send",params2)
                });
            }
        }

        $("input[name='freeTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });

        $(".input").click(function () {
            let selector = $(this).attr("id")
            parent.layer.open({
                type: 2,
                area: ['400px','350px'],
                fix: false,
                maxmin: true,
                shade: 0.3,
                title: '选择节数',
                content: prefixTime+"/selectTime",
                btn: ['确定','关闭'],
                shadeClose: true
                ,yes:function(index,layero){
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                    let result = iframeWin.submitHandler()
                    $("#"+selector).val(result)
                    parent.layer.close(index)
                    return 1;
                }
                ,cancel: function(index) {
                    return true;
                }
            });
        })
        $(".inputP").click(function () {
            let selector = $(this).attr("id")
            parent.layer.open({
                type: 2,
                area: ['400px','350px'],
                fix: false,
                maxmin: true,
                shade: 0.3,
                title: '选择节数',
                content: prefixTime+"/selectTime1",
                btn: ['确定','关闭'],
                shadeClose: true
                ,yes:function(index,layero){
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                    let result = iframeWin.submitHandler()
                    $("#"+selector).val(result)
                    parent.layer.close(index)
                    return 1;
                }
                ,cancel: function(index) {
                    return true;
                }
            });
        })
        $(".inputN").click(function () {
            let selector = $(this).attr("id")
            parent.layer.open({
                type: 2,
                area: ['400px','350px'],
                fix: false,
                maxmin: true,
                shade: 0.3,
                title: '选择节数',
                content: prefixTime+"/selectTime2",
                btn: ['确定','关闭'],
                shadeClose: true
                ,yes:function(index,layero){
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                    let result = iframeWin.submitHandler()
                    $("#"+selector).val(result)
                    parent.layer.close(index)
                    return 1;
                }
                ,cancel: function(index) {
                    return true;
                }
            });
        })

    </script>
</body>
</html>